﻿<%@ Page Title="翻单量计算" Language="C#" MasterPageFile="~/master/m.master" %>
<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<link href="../assets/css/report/AllocationDetail.css" rel="stylesheet" />
<link href="../assets/css/plugins/jQuery-DataTables/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
 <%--<link href="../assets/js/plugins/jQuery-DataTables/extensions/Select/css/select.bootstrap.min.css" rel="stylesheet" />--%>
<%--<link href="../assets/js/plugins/jQuery-DataTables/extensions/Buttons/css/buttons.bootstrap.min.css" rel="stylesheet" />--%>
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    
    <link href="../assets/css/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />

    <style>
        #search-Material {display: inline-block;width: 621px;position: absolute;left: 58px;top: 5px;color: #333;background-color: #fff;border-color: #ccc; padding: 6px;border-radius: 3px;}
        #table{margin-top: 0 !important; border-left: 0; border-right: 0;}
        .bg_blue{ background-color: #110ffd;}
        .bg_green{ background-color: #07980e;}
        .bg_red{ background-color: #fe0402;}
        /*.condition1 label{ width: 40px; text-align: right;}
        .condition1 select{ width: 129px !important;display: inline-block;}
        .condition1 input{ display: inline-block;}
        .condition1 {padding: 2px 0}*/
        .condition-container {padding-bottom: 5px;}
        .dataTables_paginate { padding-right: 10px; padding-top: 5px;}
        .dataTables_paginate {padding-top: 15px;}
        .dataTables_scroll tr.selected {border-left: 4px solid #7acf89 !important;}
        .dataTables_scroll tr.selected td{background: #dff0d8 !important;color: #222121 !important;}
        .dataTables_scrollHead{ background-color: #ffffff;}
        .dataTables_wrapper {font-size: 12px;}
        .dataTables_wrapper div.dataTables_processing {top:210px !important;}
        .footer {width:100%;}
        /*.popLayer .glyphicon{ font-size: 12px;}
        .popLayer .glyphicon-arrow-down{left: 100px;top: -3px;}
        .popLayer .glyphicon-arrow-left{left: -11px;top: -45px;}
        .popLayer .glyphicon-arrow-right{top: -45px;left: 212px;}
        .popLayer .glyphicon-arrow-up{ left: 95px;top: -112px;}
        .popLayer .infoBtn .dot { -ms-border-radius: 24px; border-radius: 24px;height: 20px;width: 20px;display: inline-block; }
        .popLayer .infoBtn .tips{width: 50px;height: 20px;display: inline-block;position: relative;top: -5px;left: 4px;}
        .popLayer .infoBtn { position: relative; top: 45px; }
        .popLayer .infotitle {z-index: 2;color: #ffffff;text-align: center;left: 20px;width: 175px;position: relative;top: 10px; font-size: 12px; font-weight: normal !important;}
        .popLayer .infotitle span{ font-weight: bold;}
        .popLayer .weekinfo { width: 212px; display: inline-block;border: solid #000 1px;padding-left: 2px;}
        .popLayer .weekinfo .info { padding: 15px 0px 0px 0px; }
        .popLayer .weekinfo .info label { margin-bottom: 0px; font-weight: normal; font-size: 12px; }
        .popLayer .weekinfo .leftinfo { width: 104px;border-right: 1px solid #ffffff;}
        .popLayer .weekinfo .rightinfo { width: 104px;padding-left: 2px; }
        .popLayer .weekinfo .Botinfo{ width: 208px;padding:0px; }
        .popLayer .weekinfo .Botinfo label{ width: 100%;padding:0px; }
        .popLayer { padding-left: 5px; font-size: 12px;}
        .popLayer tr { height: 95px; }
        .popLayer tr td{ width: 224px; border: 1px solid #ffffff;}*/
        .system-box .right-side {overflow: hidden;}
        .system-box{ min-width: 940px;}
        .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {padding: 2px;}
        .table-container{ background-color: #ffffff; padding-top: 5px !important;}
        .yuce span{ color: #ffffff; padding-left: 2px; padding-right: 2px;margin-left: 1px; cursor: default;}
        .condition-container { padding-bottom: 0px; }

        .condition-container .row {margin-right: 0px;margin-left: 0px;}
        .condition-container .col-xs-3 { max-width: 235px;}
        .condition-container .col-xs-4 { max-width: 270px;}
        .condition-container .form-group {margin-bottom: 0;}
        .condition-container .form-group label{margin-right: 3px;}
        /*下拉框覆盖样式*/
        .backselect{ color: #333;background-color: #fff;border-color: #ccc; padding: 5px 8px;}
        ul.dropdown-menu li { border: 1px solid #f1f1f1 }
        ul.dropdown-menu>li>a {margin: 0;}
        /*表头注脚*/
        .th-dot { -ms-border-radius: 16px; border-radius: 16px;height: 16px;width: 16px;display: inline-block;margin-bottom: -3px;margin-left: 10px; }
    
        /*.dataTables_scrollBody{ overflow-x: auto !important;}*/
        #search-start { position: absolute; max-width: 150px; background-color: #ffffff; border-color: #ccc; padding: 6px; border-radius: 3px; top: 5px; left: 58px; }
        #search-end { position: absolute; max-width: 150px; background-color: #ffffff; border-color: #ccc; padding: 6px; border-radius: 3px; top: 5px; left: 58px; }
        .FromToday { position: relative; top: -5px; left: -3px; /*float: right;*/ padding-left: 5px; }
        #table tbody tr { height: 35px; }
        .RedText { color: red; }
        .MaterialShortName { min-width: 120px; }
        .tips { line-height: normal; color: #bc7b21; background: #fffdcd; padding: 3px; border-bottom: 1px solid #e5e5e5; }
        .FromToday { background-color: #eee; font-weight: normal !important; }
        .CheckDate ,.ReorderDate { position: relative; top: 3px; }
        .badge-danger, .label-danger{ color: red;}
        </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
<div class="system-box">
	<div class="right-side">
        <div class="btns-container"></div>
        
	    <form class="form-horizontal">
	    <!--查询条件-->
		<div class="condition-container">
            <%--<div class="condition-title">查询条件</div>--%>
		    <div class="row" style="overflow: visible;">
		        <div class="form-group col-xs-3">
		            <label for="search-Kind" class="control-label">大类</label>
		            <select id="search-Kind" class="form-control selectpicker"  data-width="150px" data-style="backselect" data-live-search="true" multiple></select>
		        </div>
		        <div class="form-group col-xs-3">
		            <label for="search-Item" class="control-label">子项</label>
		            <select id="search-Item" class="form-control selectpicker"  data-width="150px" data-style="backselect" data-live-search="true" multiple></select>
		        </div>
		        <div class="form-group col-xs-3">
		            <label for="search-Gender" class="control-label">性别</label>
		            <select id="search-Gender" class="form-control selectpicker"  data-width="150px" data-style="backselect"></select>		        
		        </div>
		        <div class="form-group col-xs-4">
		            <label for="search-AllCzpFlag" class="control-label">畅滞销状态</label>
		            <select id="search-AllCzpFlag" class="form-control selectpicker" data-width="150px" data-style="backselect">
		                <option value="">请选择</option>
		                <option value="爆">爆</option>
		                <option value="畅">畅</option>
		                <option value="平">平</option>
		            </select>
		        </div>
		        <div class="form-group col-xs-4">
		            <label for="search-ERPFlag" class="control-label">ERP订单</label>
		            <select id="search-ERPFlag" class="form-control selectpicker" data-width="150px" data-style="backselect">
		                <option value="">请选择</option>
		                <option value="1">是</option>
		                <option value="0">否</option>
		            </select>
		        </div>
		    </div>
		    <div class="row" style="overflow: visible;">
		        <div class="form-group col-xs-3">
		            <label for="search-start" class="control-label">日期</label>
		            <input type="text" class="form-control layer-date" readonly="readonly" placeholder="开始时间" id="search-start" />	
		        </div>
		        <div class="form-group col-xs-3">
		            <label for="search-end" class="control-label">至</label>
		            <input type="text" class="form-control layer-date" readonly="readonly" placeholder="结束时间" id="search-end" />
		        </div>
		        <div class="form-group col-xs-3">
		            <label for="search-Material" class="control-label">货号</label>
		            <input id="search-Material" type="text" placeholder="多个货号以','隔开..." class="form-control" />
		        </div>

		    </div>
			<div class="cb"></div>
		</div>
        </form>

        <div class="table-container no-padding">
	    <div class="tips"><i class="fa fa-lightbulb-o"></i>&nbsp;ERP订单日期右上角的数字代表下单天数.</div>
             <table class="table table-bordered text-center" id="table" style="table-layout: fixed;min-width: 100%; margin-top: 0px !important;"></table>
        </div>
		<%--<div class="pageControl"></div>--%>
        <div id="popContainer" style="display: none;">
            <div class="popLayer">
                <table class="table table-bordered text-center" id="popTable" style="/*table-layout: fixed; width:1100px;*/"></table>
            </div>
        </div>
	</div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
<script src="../assets/js/framework.js"></script>
<script src="../assets/js/page/rScroll.js"></script>
<script src="../assets/js/page/pageControl.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
<script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
<script src="../assets/js/plugins/iCheck/icheckAll.js"></script>

<script src="../assets/js/plugins/jQuery-DataTables/jquery.dataTables.min.js"></script>
<script src="../assets/js/plugins/jQuery-DataTables/dataTables.bootstrap.js"></script>
<%--<script src="../assets/js/plugins/jQuery-DataTables/extensions/Select/js/dataTables.select.min.js"></script>--%>
<%--<script src="../assets/js/plugins/jQuery-DataTables/extensions/Buttons/js/dataTables.buttons.min.js"></script>--%>
    
<script src="../assets/js/plugins/bootstrap-select/bootstrap-select.min.js"></script>
<script src="../assets/js/plugins/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>
    
<script src="../assets/js/plugins/layer/laydate/laydate.js"></script>

<script>

    //诺米通用绑定下拉框
    var nmCommonBindList = function (controller, action, params, els, value, text, size, canNull, callback) {
        Y.API2(controller, action, params, function (data) {
            if (data.Success == false) {
                swal(data.Message, '', 'error');
            } else {
                var html = '';
                if (canNull) {
                    html = '<option value="">请选择</option>';
                }
                data.map(function (item) {
                    html += '<option value=' + item[value] + '>' + item[text] + '</option>';
                });
                els.map(function (item) {
                    $(item).empty();
                    $(item).html(html);
                    $(item).selectpicker({ size: size || 8, 'title': '请选择' });
                    $(item).selectpicker('refresh');
                });
                if (typeof callback === "function") {
                    callback();
                }
            }
        });
    }

    //大类
    var nmGetKindInfo = function (els, size, callback) {
        nmCommonBindList('Common', 'GetKindInfo', {}, els, 'KindID', 'KindName', size, false, callback);
    }
    //子项
    var nmGetItemInfo = function (els, params, size, callback) {
        nmCommonBindList('Common', 'GetItemInfo', { kindIds: params }, els, 'ItemorSub', 'ItemorSub', size, false, callback);
    }
    //性别
    var nmGetSexList = function (els, size, callback) {
        nmCommonBindList('Common', 'GetSexInfo', {}, els, 'SexId', 'SexName', size, true, callback);
    }

    var getInfoNameColor = function (name) {
        if (name == '新店') {
            return ' style="color: green;"';
        } else if (name == '老店') {
            return ' style="color: blue;"';
        } else {
            return "";
        }
    }


    $(document).ready(function () {

        //界面太大了，默认收起左边菜单
        $('.navbar-minimalize i', window.parent.document).click();

        //模块ID
        var ModuleID = Y.getUrlParam("ModuleID");
        //获取按钮
        commonUtil.loadBtnList(ModuleID, function () {
            $('.btns-container').append('<div style="clear: both;"></div>');
        });

        var Page = 1;
        var Size = 20;

        nmGetKindInfo(['#search-Kind']);
        nmGetSexList(['#search-Gender']);

        //大类获取小类
        $(document).on("change", "#search-Kind", function () {
            //console.log("触发了原生的change事件!");
            $("#search-ItemID").html('<option value="">请选择</option>');
            var ids = $(this).val();
            if (ids == "" || ids == null) {
                $('#search-Item').empty();
                $('#search-Item').selectpicker('refresh');
                return;
            }
            nmGetItemInfo(['#search-Item'], ids.join(',')); //小品类
        });

        //没有数据也初始化一下，渲染控件样式
        $('#search-Item').selectpicker({ size: 6, 'title': '请选择' });
        $('#search-Item').selectpicker('refresh');
        /*========================================================================================*/

        //计算表格高度
        var ua = navigator.userAgent.toLowerCase();
        var calcTableHeight = function () {
            var tableHeight = 0;
            //开始时候表格可能没有初始化,取默认高度40
            var headHeight = $('.dataTables_scrollHead').outerHeight() || 40;
            //提供不同浏览器兼容计算
            if (ua.indexOf('chrome') > -1) {
                tableHeight = $('.right-side').outerHeight() - $('.btns-container').outerHeight() - $('.condition-container').outerHeight() - headHeight - $('.tips').outerHeight() - 55;
            } else {
                tableHeight = $('.right-side').outerHeight() - $('.btns-container').outerHeight() - $('.condition-container').outerHeight() - headHeight - $('.tips').outerHeight()- 55;
            }
            //必须用css方式设定，直接用.height()有时候会差60px
            $('.dataTables_scrollBody').css({ height: tableHeight + 'px' });
            return calcTableHeight;
        }

        /*========================================================================================*/
        //数据列表
        var table = null;
        var opts = {
            language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" },
            scrollX: true,
            searching: false,
            paging: true,
            info: false,
            ordering: false,
            lengthChange: false,
            processing: true,
            //autoWidth: true,
            pagingType: "full_numbers",
            scrollY: calcTableHeight(),//为了分页控件固定在下方
            scrollCollapse: false, //当显示更少的记录时，是否允许表格减少高度
            serverSide: true, //开启服务器分页模式
            pageLength: Size,
            initComplete: function (settings, json) {
                //表格初始化完毕立即计算一次
                calcTableHeight();
            },
            ajax: {
                url: '/api.ashx?c=GoodsReorderTotalDemand&a=GetGoodsReorderTotalDemandList&u=',
                type: "POST",
                //data: {},//提交参数
                data: function (d) {
                    var kindArr = $('#search-Kind').val();
                    var kinds = (kindArr != null) ? kindArr.join(',') : "";
                    var itemArr = $('#search-Item').val();
                    var items = (itemArr != null) ? itemArr.join(',') : "";
                    //debugger 
                    d.KindID = kinds;
                    d.ItemOrSub = items;
                    d.SexID = $('#search-Gender').val();
                    d.AllCzpFlagNow = $('#search-AllCzpFlag').val();//畅滞销状态
                    d.ERPFlag = $('#search-ERPFlag').val();
                    d.StartDate = $('#search-start').val();//开始时间
                    d.EndDate = $('#search-end').val();//结束时间
                    d.MaterialID = $('#search-Material').val();//货号
                    //debugger 
                    d.Page = (d.start / d.length) + 1;
                    d.Size = d.length;
                },
                dataSrc: function (res) {//dataSrc函数应该return一个【实体数组】供渲染表格
                    if (res.Success === false) {
                        swal(res.Message, '', 'error');
                        return [];
                    } else {
                        var items = res.Data.Items;
                        for (var i = 0; i < items.length; i++) {
                            res.Data.Items[i].RowId = i + 1;
                        };
                        //debugger 
                        Page = res.Data.Page;
                        res.draw = table.ajax.params().draw;
                        res.recordsTotal = res.Data.RecordCount;
                        res.recordsFiltered = res.Data.RecordCount;

                        return res.Data.Items;
                    }
                }
            },
            columns: [
                { title: "行号", "data": "RowId", "width": "30px", className: "text-center RowId hide", defaultContent: "" },
                {
                    title: '<input type="checkbox" name="checkAllDetail" class="checkAll" value="all" />',
                    data: null, "width": "20px", className: "text-center",
                    render: function (data, type, row, meta) {
                        return '<input type="checkbox" name="checkItemDetail" class="checkItem" value="" />';
                    }
                },
                {
                     title: "翻单日期", "data": "", "width": "70px", className: "text-center", defaultContent: "",
                     render: function (data, type, row, meta) {
                         return '<div>\
                                    <span class="ReorderDate">' + (row.ReorderDate || '') + '</span>\
                                </div>';
                     }
                },
                {
                    title: "ERP订单日期", "data": "", "width": "100px", className: "text-center", defaultContent: "",
                    render: function (data, type, row, meta) {
                        return '<div>\
                                    <span class="CheckDate">' + (row.CheckDate || '') + '</span>\
                                    <span class="badge badge-danger FromToday">' + (row.FromToday || '') + '</span>\
                                </div>';
                    }
                },
                { title: "ERP订单号", "data": "BillNo", "width": "110px", className: "text-center KindName", defaultContent: "" },
                { title: "订单到货日期", "data": "StartShipDate", "width": "80px", className: "text-center KindName", defaultContent: "" },
                { title: "订单数量", "data": "ErpOrderQty", "width": "30px", className: "text-center KindName", defaultContent: "0" },


                { title: "大类", "data": "KindName", "width": "30px", className: "text-center KindName", defaultContent: "" },
                { title: "性别", "data": "SexName", "width": "30px", className: "text-center SexName", defaultContent: "" },
                { title: "子项", "data": "ItemOrSub", "width": "100px", className: "text-center ItemOrSub", defaultContent: "" },
                { title: "款号", "data": "StyleCode", "width": "100px", className: "text-center", defaultContent: "" },
                {
                    title: "货号", "data": "", "width": "110px", className: "text-center", defaultContent: "",
                    render: function (data, type, row, meta) {
                        return '<a class="MaterialID">' + row.MaterialID +'</a>';
                    }
                },
                { title: "货品简称", "data": "MaterialShortName", "width": "", className: "text-center MaterialShortName", defaultContent: "" },
                { title: "季节", "data": "SeasonName", "width": "30px", className: "text-center ", defaultContent: "" },
                { title: "颜色", "data": "ColorName", "width": "30px", className: "text-center ", defaultContent: "" },
                { title: "上市天数", "data": "MoveDays", "width": "30px", className: "text-center ", defaultContent: "" },
                { title: "标准陈列量", "data": "DisplayQty", "width": "40px", className: "text-center ", defaultContent: "" },
                { title: "生产周期", "data": "ProductDays", "width": "30px", className: "text-center ", defaultContent: "" },
                { title: "畅滞销状态", "data": "AllCzpFlagNow", "width": "40px", className: "text-center ", defaultContent: "" },
                { title: "预计销售", "data": "MonthSaleQty", "width": "60px", className: "text-center ", defaultContent: "" },
                { title: "期末陈列需求", "data": "PlayReqQty", "width": "45px", className: "text-center ", defaultContent: "" },
                { title: "翻单总需求", "data": "TotalQty", "width": "40px", className: "text-center ", defaultContent: "" },
                { title: "翻单时库存", "data": "InitQty", "width": "60px", className: "text-center ", defaultContent: "" },
                { title: "翻单到货后库存", "data": "StockQty", "width": "60px", className: "text-center ", defaultContent: "" },
                { title: "建议翻单量", "data": "OrderQty", "width": "40px", className: "text-center ", defaultContent: "" },
                { title: "翻单到店日期", "data": "ArriverDate", "width": "80px", className: "text-center ", defaultContent: "" },
                { title: "销售周期", "data": "SaleDays", "width": "30px", className: "text-center ", defaultContent: "" },
                { title: "供应商名称", "data": "VendCustName", "width": "100px", className: "text-center ", defaultContent: "" },
                { title: "供应商代码", "data": "VendCustCode", "width": "60px", className: "text-center ", defaultContent: "" },
                { title: "成本价", "data": "CostPrice", "width": "60px", className: "text-center ", defaultContent: "" },
                { title: "综合排名", "data": "RowNumber", "width": "60px", className: "text-center ", defaultContent: "" },
            ]
        }
        table = $('#table').DataTable(opts);
        table.on( 'init.dt', function () {
            $.fn.dataTable.tables({ visible: true, api: true }).columns.adjust();
        });

        //加载列表数据
        var loadList = function () {
            table.ajax.reload(function () {
                //debugger 
                //重新计算列宽
                table.columns.adjust().draw();

            }, true);
            //debugger
        }

        //查询按钮
        $('.btns-container').on('click', '#btn-search', function () {
            Page = 1;
            loadList();
        });

        //计算按钮
        $('.btns-container').on('click', '#calculateBtn', function () {

            var materialIdArr = [];
            var checkedItems = $('#table .checkItem:checked');
            checkedItems.each(function () {
                var materialId = $(this).parents('tr').find('.MaterialID').text();
                materialIdArr.push(materialId);
            });

            var materialIds = materialIdArr.join(',');
            if (materialIds == '') {
                swal("请选择要计算的行", '', 'error');
                return false;
            }

            layer.msg('正在计算，请耐心等待',
                {
                    icon: 16,
                    shade: 0.5,
                    time: 0,
                    maxWidth: 200,
                    area: ['230px', '75px']
                });

            Y.API2("GoodsReorderTotalDemand", "CalGoodsReorderTotalDemand",
                {
                    MaterialID: materialIds
                },
                function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        //table.ajax.reload(function () {
                        //    //debugger 
                        //    //重新计算列宽
                        //    table.columns.adjust().draw();
                        //}, false);
                    }
                });
        });

        //单行点击高亮
        $('#table').on('click', 'tr', function () {
            table.$('tr').removeClass('selected');
            $(this).addClass('selected');
        });


        $('.table-container').on('click', '.checkAll', function () {
            var state = $(this).prop('checked');
            var selectArr = $('#table .checkItem');
            selectArr.each(function () {
                $(this).prop("checked", state);
            });
        });

        $('.table-container').on('click', '.checkItem', function () {
            var allItems = $('#table .checkItem').length;
            var checkedItems = $('#table .checkItem:checked').length;
            if (allItems == checkedItems) {
                $('#table_wrapper .dataTables_scrollHead .checkAll').prop("checked", true);
            } else {
                $('#table_wrapper .dataTables_scrollHead .checkAll').prop("checked", false);
            }
        });

        var selectedRow = "0";

        //弹窗
        var getDetail = function (materialId) {
            Y.API2("GoodsReorderTotalDemand", "GetGoodsReorderTotalDemandItem",
                {
                    MaterialID: materialId
                },
                function (data) {
                    if (data.Success == false) {
                        swal("无法查看详细：" + data.Message, '', 'error');
                    } else {
                        //非弹窗时候，popLayer只有一个
                        var tb = $('.popLayer').find('#popTable');
                        //
                       var tbHtml = '<thead><tr>\
                                        <td>货号</td>\
                                        <td>店类型</td>\
                                        <td>店铺级别</td>\
                                        <td>店铺数</td>\
                                        <td>日均销</td>\
                                        <td>月份</td>\
                                        <td>本月销售天数</td>\
                                        <td>预计销售</td>\
                                      </tr>';
                        tbHtml += "</thead><tbody>";
                        if (data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                var tdHtml = '<tr>\
                                        <td>'+ data[i].MaterialID + '</td>\
                                        <td'+ getInfoNameColor(data[i].ShopType) + '>' + data[i].ShopType + '</td>\
                                        <td>'+ data[i].InfoName + '</td>\
                                        <td>'+ data[i].ShopNum + '</td>\
                                        <td>'+ (data[i].DaySaleQty || '') + '</td>\
                                        <td>'+ data[i].month + '</td>\
                                        <td>'+ data[i].MonthDays + '</td>\
                                        <td>'+ data[i].MonthSaleQty + '</td>\
                                      </tr>';
                                tbHtml += tdHtml;
                            }
                        } else {
                            tbHtml += '<tr><td colspan="8">表中数据为空</td></tr>';
                        }
                        tbHtml += "</tbody>";
                        tb.html(tbHtml);

                        layer.open({
                            type: 1,
                            skin: 'layui-layer-demo', //样式类名
                            anim: 2,
                            title: "计算翻单下单辅助信息",
                            btn: '确定',
                            area: ['1000px', '450px'],
                            shadeClose: true, //开启遮罩关闭
                            content: $('#popContainer').html(),
                            end: function (index, layero) {
                                selectedRow = "0";
                            }
                        });
                    }
                });
        }

        //单行点击弹窗
        $('#table').on('click', '.MaterialID', function () {
            //获取当前行高亮
            var tr = $(this).parents('tr');
            $(tr).addClass('selected');

            //获取行号
            var currentRow = $(tr).find('.RowId').text();
            //如果是重复的就不再继续了，防止双击出现两个弹窗
            if (selectedRow == currentRow) {
                selectedRow = currentRow;
                return false;
            }

            selectedRow = currentRow;
            //获取选中行

            var materialId = $(tr).find('.MaterialID').text();
            getDetail(materialId);

        });

        //重新计算表格高度
        $(window).resize(function () {
            calcTableHeight();
            //重新计算列宽
            //table.columns.adjust().draw();
        });

        calcTableHeight();

        //初始化日期控件
        var searchstart = {
            elem: "#search-start",
            format: "YYYY-MM-DD",
            min: "2015-12-01",
            max: "2099-12-01",
            istime: false,
            istoday: false,
            choose: function (datas) {
                searchend.min = datas;
                searchend.start = datas
            }
        };
        var searchend = {
            elem: "#search-end",
            format: "YYYY-MM-DD",
            min: "2015-12-01",
            max: "2099-12-01",
            istime: false,
            istoday: false,
            choose: function (datas) {
                searchstart.max = datas
            }
        };
        laydate(searchstart);
        laydate(searchend);

        //导出
        $(document).on("click", "#exportBtn", function () {
            var conditionsArr = [];

            var kindArr = $('#search-Kind').val();
            var kinds = "";
            if (kindArr != null) {
                kinds = kindArr.join(',');
            }

            var itemArr = $('#search-Item').val();
            var items = "";
            if (itemArr != null) {
                items = itemArr.join(',');
            }

            var sexID = $('#search-Gender').val();
            var allCzpFlagNow = $('#search-AllCzpFlag').val();
            var erpFlag = $('#search-ERPFlag').val();
            var startDate = $('#search-start').val();
            var endDate = $('#search-end').val();
            var materialID = $('#search-Material').val();

            if (!Y.checkNull(kinds)) {
                conditionsArr.push({ connector: "and", column: "kind.KindID", operator: "in_shopids", value: kinds });
            }
            if (!Y.checkNull(items)) {
                conditionsArr.push({ connector: "and", column: "a.ItemOrSub", operator: "in_shopids", value: items });
            }
            if (!Y.checkNull(sexID)) {
                conditionsArr.push({ connector: "and", column: "sex.SexID", operator: "=", value: sexID });
            }
            if (!Y.checkNull(allCzpFlagNow)) {
                conditionsArr.push({ connector: "and", column: "a.AllCzpFlagNow", operator: "=", value: allCzpFlagNow });
            }
            if (!Y.checkNull(erpFlag)) {
                conditionsArr.push({ connector: "and", column: "a.ERPFlag", operator: "=", value: erpFlag });
            }
            if (!Y.checkNull(startDate)) {
                conditionsArr.push({ connector: "and", column: "a.ReorderDate", operator: ">=", value: startDate });
            }
            if (!Y.checkNull(endDate)) {
                conditionsArr.push({ connector: "and", column: "a.ReorderDate", operator: "<=" , value: endDate });
            }
            if (!Y.checkNull(materialID)) {
                conditionsArr.push({ connector: "and", column: "a.MaterialID", operator: "in_shopids", value: materialID });
            }
            conditionsArr = JSON.stringify(conditionsArr);
            var tempParam = {};
            tempParam.filename = "翻单量计算,翻单量计算辅助信息";
            tempParam.filetype = "GOODSREORDERTOTALDEMAMD,GOODSREORDERTOTALDEMAMDITEM";
            tempParam.conditions = encodeURIComponent(conditionsArr);
            var t = $.ExportAll(tempParam);
        });
    })
</script>
</asp:Content>

